package XSSDemo.servlet;

import XSSDemo.pojo.MessageInfo;
import XSSDemo.service.MessageInfoService;
import XSSDemo.service.impl.MessageInfoServiceImpl;

import java.io.IOException;
import java.util.List;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;



public class ShowServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // TODO Auto-generated method stub

        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        ShowMessage(req,resp);

    }

    public void ShowMessage(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // TODO Auto-generated method stub

        MessageInfoService msginfo = new MessageInfoServiceImpl();

        List<MessageInfo> msg = msginfo.MessageInfoShowService();
        if( msg != null){
            req.setAttribute("msg", msg);
            req.getRequestDispatcher("/message.jsp").forward(req, resp);
            return ;
        }

    }
}
